//
//  HEClander.m
//  HEClander
//
//  Created by User on 16/5/16.
//  Copyright © 2016年 User. All rights reserved.
//

#import "HEClander.h"

#import "TableViewCell.h"
#import "DateTools.h"
#import "TableViewCellButton.h"
#import "RemaindView.h"

#define WIDTH [[UIScreen mainScreen] bounds].size.width
#define HEIGHT [[UIScreen mainScreen] bounds].size.height

#define LEFT_WIDTH (3.0f*(WIDTH/414.0))
#define VIEW_WIDTH (58.0f*(WIDTH/414.0))
#define VIEW_HEIGHT (50.0f*(WIDTH/414.0))
#define RILIVIEW_WIDTH 70.0f
#define TOPVIEW_COLOR NavBackColor


UITableView *table;
UIScrollView *weekScroll;

UIView *MoveView;
//大日历
UIImageView *Moveimage;
UIImageView *Startimage;
UIView *startView;
UIView *endView;
UIButton *startbutt;
TableViewCellButton *movebutt;

UILabel *startLab;
UILabel *endLab;

UIPanGestureRecognizer *panGestureRecognizer1;
UIPanGestureRecognizer *panGestureRecognizer2;
//星期日历
UIImageView *weekMoveimage;
UIImageView *weekStartimage;
UIView *weekstartView;
UIView *weekendView;
UIButton *weekstartbutt;
UIButton *weekmovebutt;

UILabel *weekstartLab;
UILabel *weekendLab;

UIPanGestureRecognizer *weekpanGestureRecognizer1;
UIPanGestureRecognizer *weekpanGestureRecognizer2;

UISwipeGestureRecognizer *upSwipe;
UISwipeGestureRecognizer *downSwipe;

UISwipeGestureRecognizer *leftSwipe;
UISwipeGestureRecognizer *rightSwipe;

NSMutableArray *dateArr;
NSMutableArray *dateArr1;
NSMutableArray *ConnectImageArr;
NSMutableArray *WeekRemaindArr;
NSMutableArray *WeekButtArr;

UILabel *TitleLabel;

NSDate *endDate;
//
NSDate *CeshiDate;
NSDate *CeshiDate1;
UIView *corview;
RemaindView *remanidView;

UIView *view1;
UITableView *table1;

int ant;
int tableCount;
int endX;
int endY;
int row;
int monthOne;
int weekmonthOne;
int todayNumber;

int count;
int weekCount;
int addcount;
int tableHeightNum;

CGFloat contentOffsetX;

CGFloat oldContentOffsetX;

CGFloat newContentOffsetX;

BOOL isExpand;
BOOL isMove;
BOOL isButtClick;
BOOL isToday;

int number;

int age;
int current;
int lastClick;
int weekRemaind;

UIButton *leftButt;
UIButton *rightButt;

CGPoint point;
@implementation HEClander

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        CeshiDate = [NSDate date];
        CeshiDate1 = [NSDate date];
        tableCount = 6;
        
        isExpand = YES;
        [self setProperty];
        self.backgroundColor = NavBackColor;
        monthOne = [DateTools setdate:CeshiDate];
        weekmonthOne = [DateTools setdate:[NSDate date]];
        todayNumber = (int)[[DateTools getDateInfobydate:[NSDate date]] day];
        
        point = [self getXYbyDay:todayNumber];
        
        lastClick = todayNumber;
        [self getCount];
        
        ConnectImageArr = [[NSMutableArray alloc] init];
        _remaindArr = [[NSMutableArray alloc] init];
        WeekRemaindArr = [[NSMutableArray alloc] init];
        WeekButtArr = [[NSMutableArray alloc] init];
        dateArr = [DateTools getDatesourcebyDate:CeshiDate];
        dateArr1 = [DateTools getDatesourcebyDate:CeshiDate1];
        //NSLog(@"0000------------------------    %@",dateArr);
        
        leftButt = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        //    [leftButt setTitle:@"上个月" forState:UIControlStateNormal];
        [leftButt setImage:[UIImage imageNamed:@"HY_date_icon_arrow_left"] forState:UIControlStateNormal];
        leftButt.tag = 100;
        leftButt.backgroundColor = TOPVIEW_COLOR;
        [leftButt addTarget:self action:@selector(ChangeMonth:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:leftButt];
        
        rightButt = [[UIButton alloc] initWithFrame:CGRectMake(WIDTH - 30, 0, 30, 30)];
        //    [rightButt setTitle:@"下个月" forState:UIControlStateNormal];
        [rightButt setImage:[UIImage imageNamed:@"HY_date_icon_arrow_right"] forState:UIControlStateNormal];
        rightButt.tag = 200;
        rightButt.backgroundColor = TOPVIEW_COLOR;
        [rightButt addTarget:self action:@selector(ChangeMonth:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:rightButt];
        
        //添加标题年月 label
        TitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, WIDTH - 60, 30)];
        TitleLabel.backgroundColor = TOPVIEW_COLOR;
        NSString *title = [[DateTools getYearAndMonth:CeshiDate] objectAtIndex:0];
        TitleLabel.text = title;
        TitleLabel.font = [UIFont boldSystemFontOfSize:15];
        TitleLabel.textAlignment = NSTextAlignmentCenter;
        TitleLabel.textColor = UIColorFromRGB(0xa9b8e3);
        //        [ViewTool setLableFont14:TitleLabel];
        [self addSubview:TitleLabel];
        
        NSArray *weekArr = [NSArray arrayWithObjects:@"日",@"一",@"二",@"三",@"四",@"五",@"六", nil];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, WIDTH, 40)];
        label.backgroundColor = TOPVIEW_COLOR;
        
        [self addSubview:label];
        
        for (int i = 0; i < 7; i ++) {
            UILabel *week = [[UILabel alloc] initWithFrame:CGRectMake(LEFT_WIDTH+VIEW_WIDTH*i, 30, VIEW_WIDTH, 40)];
            week.text = [weekArr objectAtIndex:i];
            week.textColor = UIColorFromRGB(0xb6c3ea);
            week.textAlignment = NSTextAlignmentCenter;
            week.backgroundColor = TOPVIEW_COLOR;
            [ViewTool setLableFont14:week];
            
            [self addSubview:week];
        }
        [self addScrollview];
        [self addRemaind];
        [self addTable];
    }
    return self;
}

- (void)addRemaind
{
    
//    NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"1",@"2",@"3", nil];
    remanidView = [[RemaindView alloc] initWithFrame:CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, WIDTH-LEFT_WIDTH, VIEW_HEIGHT*tableHeightNum)];
//    [remanidView setArr:arr];
    
    [self addSubview:remanidView];
    for (int i = 0; i < 6; i ++) {
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10+VIEW_HEIGHT*i, WIDTH, 40*(HEIGHT/736.0))];
        
        //img.image = [UIImage imageNamed:_ConnectImageName];
        img.tag = i;
        
        [remanidView addSubview:img];
        [remanidView sendSubviewToBack:img];
        [ConnectImageArr addObject:img];
    }
}

- (void)setProperty
{
    _ConnectImageName = @"HY_date_bg_checkbox_selected_middle";
    
    _startbuttImageName = @"HY_date_bg_radio_selected";
    _endbuttImageName = @"HY_date_bg_radio_selected";
    
    _startBottomLabText = @"始";
    _endBottomLabText = @"终";
    
}

- (void)ChangeMonth:(UIButton *)butt
{
    [dateArr removeAllObjects];
    int y = [self getDayCountOfMonth:CeshiDate];
    if (monthOne == 7) {
        monthOne = 0;
    }
    int num = ceilf((float)(y + monthOne)/7.0);
    
    if (isExpand == NO) {
        if (butt.tag == 100) {
            if (weekScroll.contentOffset.x > 0) {
                addcount --;
//                NSLog(@"num -------   %d",addcount);
                weekScroll.contentOffset = CGPointMake(VIEW_WIDTH*7*(weekCount+addcount), 0);
            }
        }
        if (butt.tag == 200) {
            if (weekScroll.contentOffset.x < VIEW_WIDTH*7*(num - 1)) {
                addcount ++;
//                NSLog(@"num ++++++++   %d",addcount);
                if (weekCount+addcount > num){
                    
                    addcount --;
                    return;
                }
                weekScroll.contentOffset = CGPointMake(VIEW_WIDTH*7*(weekCount+addcount), 0);
            }
        }
        return;
    }
    //左
    if (butt.tag == 100) {
        
        CeshiDate = [DateTools changeMonth:CeshiDate add:-1];
    }
    //右
    if (butt.tag == 200) {
        
        CeshiDate = [DateTools changeMonth:CeshiDate add:1];
    }
    
    NSDateComponents *comps = [DateTools getDateInfobydate:CeshiDate];
    NSString *str1= [NSString stringWithFormat:@"%d",(int)comps.year];
    NSString *str2= [NSString stringWithFormat:@"%d",(int)comps.month];
    NSString *str3= [NSString stringWithFormat:@"%d",(int)comps.day];
    
    if ([str2 intValue]<10) {
        str2 = [NSString stringWithFormat:@"0%@",str2];
    }
    if ([str3 intValue]<10) {
        str3 = [NSString stringWithFormat:@"0%@",str3];
    }
    for (UIImageView *img in ConnectImageArr) {
        img.backgroundColor = [UIColor clearColor];
    }
    Startimage.frame = CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0));
    Moveimage.frame = CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0));
    
    [self starButtonClicked:butt str1:str1 str2:str2 str3:str3];
    
    dateArr = [DateTools getDatesourcebyDate:CeshiDate];
    monthOne = [DateTools setdate:CeshiDate];
    NSMutableArray *arr = [DateTools getYearAndMonth:CeshiDate];
    
    TitleLabel.text = [arr objectAtIndex:0];
    
    [MoveView removeFromSuperview];
    MoveView = nil;
    [self addTable];
    
//    [table reloadData];
    
    int any = (int)[DateTools getDateInfobydate:CeshiDate].day;
    int any1 = (int)[DateTools getDateInfobydate:[NSDate date]].day;
    
    if (any == any1) {
        [self isHaveRemaind:[NSString stringWithFormat:@"%d",any]];
    }
}

- (void)change
{
    NSDateComponents *comps = [DateTools getDateInfobydate:CeshiDate];
    NSString *str1= [NSString stringWithFormat:@"%d",(int)comps.year];
    NSString *str2= [NSString stringWithFormat:@"%d",(int)comps.month];
    NSString *str3= [NSString stringWithFormat:@"%d",(int)comps.day];
    
    if ([str2 intValue]<10) {
        str2 = [NSString stringWithFormat:@"0%@",str2];
    }
    if ([str3 intValue]<10) {
        str3 = [NSString stringWithFormat:@"0%@",str3];
    }
    for (UIImageView *img in ConnectImageArr) {
        img.backgroundColor = [UIColor clearColor];
    }
    Startimage.frame = CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0));
    Moveimage.frame = CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0));
    NSString *str4 = @"01";
    
    NSDateComponents *com = [DateTools getDateInfobydate:[NSDate date]];
        int year = (int)com.year;
        int month = (int)com.month;
        
        if ([str1 intValue] == year && [str2 intValue] == month) {
            str4 = str3;
        }
    
    if (age == current) {
        if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(currentSelectedDate: DoubleSelected:Year:Month:
                                                                                          )]){
            [self.HEClanderDelegate currentSelectedDate:str4 DoubleSelected:str3 Year:str1 Month:str2];
        }
    }
}

- (void)todoSomething:(id)sender
{
    [self change];
}

- (void)starButtonClicked:(id)sender str1:(NSString *)str1 str2:(NSString *)str2 str3:(NSString *)str3
{
    //先将未到时间执行前的任务取消。
    [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(todoSomething:) object:sender];
    [self performSelector:@selector(todoSomething:) withObject:sender afterDelay:0.5f];
}

- (void)getCount
{
    int any = (int)[DateTools getNumberOfDaysInMonthbydate:CeshiDate];
    if (monthOne == 7) {
        monthOne = 0;
    }
    int todayNum = any + monthOne;
    int num = ceilf((float)(todayNum/7.0f));
    tableHeightNum = num;
}

- (void)refreshTableHeight
{
    self.frame = CGRectMake(0, 0, WIDTH, 75+VIEW_HEIGHT*tableHeightNum + 20);
    if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(clanderDragUpAndDown
                                                                                      )]){
        [self.HEClanderDelegate clanderDragUpAndDown];
    }
}

//添加大日历
- (void)addTable
{
    [self getCount];
    MoveView = [[UIView alloc] initWithFrame:CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, WIDTH-LEFT_WIDTH, VIEW_HEIGHT*tableHeightNum+15)];
    
    table = [[UITableView alloc] initWithFrame:MoveView.bounds style:UITableViewStylePlain];
    
    table.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
    table.tag = 0;
    table.delegate = self;
    table.dataSource = self;
    table.bounces = NO;
    table.scrollEnabled = NO;
    table.showsVerticalScrollIndicator = NO;
    table.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    //    MoveView.backgroundColor = NavBackColor;
    [self addSubview:MoveView];
    MoveView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
    
    startView = [[UIView alloc] init];
    endView = [[UIView alloc] init];
    
    startbutt = [[UIButton alloc] initWithFrame:CGRectMake(10*(WIDTH/414.0), 10*(HEIGHT/736.0), 40*(WIDTH/414.0), 40*(HEIGHT/736.0))];
    movebutt = [[TableViewCellButton alloc] initWithFrame:CGRectMake(10*(WIDTH/414.0), 10*(HEIGHT/736.0), 40*(WIDTH/414.0), 40*(HEIGHT/736.0))];
    movebutt.roundView.image = [UIImage imageNamed:@"HY_date_icon_point_selected"];
    
    int any = (int)[DateTools getDateInfobydate:CeshiDate].day;
    int any1 = (int)[DateTools getDateInfobydate:[NSDate date]].day;
    
    if (any == any1) {
        [self isHaveRemaind:[NSString stringWithFormat:@"%d",any]];
    }
    
    CGPoint point = [self getXYbyDay:any];
    int x = point.x;
    int y = point.y;
    startView.frame = CGRectMake(VIEW_WIDTH*(x-1), VIEW_HEIGHT*y, VIEW_WIDTH, VIEW_HEIGHT);
    endView.frame = CGRectMake(VIEW_WIDTH*(x-1), VIEW_HEIGHT*y, VIEW_WIDTH, VIEW_HEIGHT);
    
    int ceshiYear = (int)[DateTools getDateInfobydate:CeshiDate].year;
    int ceshiMonth = (int)[DateTools getDateInfobydate:CeshiDate].month;
    
    int todayYear = (int)[DateTools getDateInfobydate:[NSDate date]].year;
    int todayMonth = (int)[DateTools getDateInfobydate:[NSDate date]].month;
    int todayDay = (int)[DateTools getDateInfobydate:[NSDate date]].day;
    
    [startbutt setTitle:@"今" forState:UIControlStateNormal];
    [movebutt setTitle:@"今"forState:UIControlStateNormal];
    
    if (ceshiYear == todayYear && ceshiMonth == todayMonth) {
        startView.hidden = NO;
        endView.hidden = NO;
        isToday = YES;
    }
    else{
//        NSLog(@" qi ta 000000 ---------------");
        startView.hidden = YES;
        endView.hidden = YES;
        isToday = NO;
    }
    
    [table addSubview:startView];
    [table addSubview:endView];
    
    startLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, VIEW_WIDTH, 20)];
    startLab.textAlignment = NSTextAlignmentCenter;
    startLab.textColor = blackFontColor;
    startLab.font = [UIFont systemFontOfSize:14];
    
    endLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, VIEW_WIDTH, 20)];
    endLab.textAlignment = NSTextAlignmentCenter;
    endLab.textColor = blackFontColor;
    endLab.font = [UIFont systemFontOfSize:14];
    
    [startView addSubview:startLab];
    [endView addSubview:endLab];
    
    //    startbutt.layer.cornerRadius = 25;
    //    startbutt.clipsToBounds = YES;
    startbutt.tag = 0;
    //    startbutt.alpha = 0.8;
    [startbutt setBackgroundImage:[UIImage imageNamed:_startbuttImageName] forState:UIControlStateNormal];
    //    [startbutt setImage:[UIImage imageNamed:_startbuttImageName] forState:UIControlStateNormal];
    //    startbutt.backgroundColor = [UIColor yellowColor];
    [startbutt addTarget:self action:@selector(buttclick:) forControlEvents:UIControlEventTouchUpInside];
    [ViewTool setLableFont14:startbutt.titleLabel];
    
    //    movebutt.layer.cornerRadius = 25;
    //    movebutt.clipsToBounds = YES;
    //    [movebutt setTitle:@"今" forState:UIControlStateNormal];
    [movebutt setBackgroundImage:[UIImage imageNamed:_startbuttImageName] forState:UIControlStateNormal];
    //    movebutt.backgroundColor = [UIColor purpleColor];
    movebutt.tag = 1;
    //    movebutt.alpha = 0.8;
    [movebutt addTarget:self action:@selector(buttclick:) forControlEvents:UIControlEventTouchUpInside];
    [ViewTool setLableFont14:movebutt.titleLabel];
    
    Startimage = [[UIImageView alloc] initWithFrame:CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0))];
    //    Startimage.image = [UIImage imageNamed:_ConnectImageName];
    Startimage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:_ConnectImageName]];
    //    Startimage.alpha = 0.75;
//    [MoveView addSubview:Startimage];
    
    Moveimage = [[UIImageView alloc] initWithFrame:CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0))];
    //    Moveimage.image = [UIImage imageNamed:_ConnectImageName];
    Moveimage.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:_ConnectImageName]];
    //    Moveimage.alpha = 0.75;
    
//    [MoveView addSubview:Moveimage];
    [remanidView addSubview:Startimage];
    [remanidView sendSubviewToBack:Startimage];
    [remanidView addSubview:Moveimage];
    [remanidView sendSubviewToBack:Moveimage];    
    
    [startView addSubview:startbutt];
    [endView addSubview:movebutt];
    [MoveView addSubview:table];
    
    panGestureRecognizer1 = [[UIPanGestureRecognizer alloc] initWithTarget:self
                                                                    action:@selector(handlePanGestures1:)];
    
    panGestureRecognizer1.delegate = self;
    panGestureRecognizer1.minimumNumberOfTouches = 1;
    panGestureRecognizer1.maximumNumberOfTouches = 1;
    
    panGestureRecognizer2 = [[UIPanGestureRecognizer alloc] initWithTarget:self
                                                                    action:@selector(handlePanGestures2:)];
    panGestureRecognizer2.delegate = self;
    panGestureRecognizer2.minimumNumberOfTouches = 1;
    panGestureRecognizer2.maximumNumberOfTouches = 1;
    
    [startView addGestureRecognizer:panGestureRecognizer1];
    [endView addGestureRecognizer:panGestureRecognizer2];
    
    //上下 拖拽
    leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
    leftSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
    [table addGestureRecognizer:leftSwipe];
    
    rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
    rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
    [table addGestureRecognizer:rightSwipe];
    
    upSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
    upSwipe.direction = UISwipeGestureRecognizerDirectionUp;
    [table addGestureRecognizer:upSwipe];
    
    downSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
    downSwipe.direction = UISwipeGestureRecognizerDirectionDown;
    [table addGestureRecognizer:downSwipe];
    
    [self refreshTableHeight];
    
}

//添加星期 日历
- (void)addScrollview
{
    if (monthOne == 7) {
        monthOne = 0;
    }
    int a = monthOne + (int)[DateTools getNumberOfDaysInMonthbydate:[NSDate date]];
    int ant = ceilf((float)(a/7.0));
    
    weekScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, VIEW_WIDTH*7, VIEW_HEIGHT+10)];
    
    weekScroll.delegate = self;
    weekScroll.pagingEnabled = YES;
    weekScroll.bounces = NO;
    weekScroll.backgroundColor = UIColorFromRGB(0x4c64a4);
    weekScroll.showsHorizontalScrollIndicator = NO;
    weekScroll.contentSize = CGSizeMake(VIEW_WIDTH*7*ant, 0);
    weekScroll.hidden = YES;

    int any = todayNumber;
//    CGPoint point = [self getXYbyDay:any];
    int y = point.y;
    weekScroll.contentOffset = CGPointMake(LEFT_WIDTH+VIEW_WIDTH*7*y, 0);
    weekCount = y;
    oldContentOffsetX = weekScroll.contentOffset.x;
    corview = [[UIView alloc] initWithFrame:CGRectMake(VIEW_WIDTH*7, RILIVIEW_WIDTH, WIDTH - VIEW_WIDTH*7, VIEW_HEIGHT+10)];
    corview.backgroundColor = UIColorFromRGB(0x4c64a4);
    [self addSubview:corview];
    
    [self addSubview:weekScroll];
    
    weekstartView = [[UIView alloc] init];
    weekendView = [[UIView alloc] init];
    //weekstartView.backgroundColor = [UIColor redColor];
    if (weekmonthOne == 7) {
        weekmonthOne = 0;
    }
    int todayNum = any + weekmonthOne;
//    NSLog(@"mmmmmmmmmm ---------------   %d",todayNum);
    weekstartView.frame = CGRectMake(VIEW_WIDTH*(todayNum-1), 0, VIEW_WIDTH, VIEW_HEIGHT+10);
    weekendView.frame = CGRectMake(VIEW_WIDTH*(todayNum-1), 0, VIEW_WIDTH, VIEW_HEIGHT+10);
    
    
    weekstartLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 55, VIEW_WIDTH, 20)];
    weekstartLab.textAlignment = NSTextAlignmentCenter;
    weekstartLab.textColor = blackFontColor;
    weekstartLab.font = [UIFont systemFontOfSize:14];
    
    weekendLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 55, VIEW_WIDTH, 20)];
    weekendLab.textAlignment = NSTextAlignmentCenter;
    weekendLab.textColor = blackFontColor;
    weekendLab.font = [UIFont systemFontOfSize:14];
    
    [weekstartView addSubview:weekstartLab];
    [weekendView addSubview:weekendLab];
    
    weekstartbutt = [[UIButton alloc] initWithFrame:CGRectMake(10*(WIDTH/414.0), 15*(HEIGHT/736.0), 40*(WIDTH/414.0), 40*(HEIGHT/736.0))];
    
    weekstartbutt.tag = 3;
    [ViewTool setLableFont14:weekstartbutt.titleLabel];
    [weekstartbutt setBackgroundImage:[UIImage imageNamed:_startbuttImageName] forState:UIControlStateNormal];
    
    [weekstartbutt addTarget:self action:@selector(weekclick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    weekmovebutt = [[UIButton alloc] initWithFrame:CGRectMake(10*(WIDTH/414.0), 15*(HEIGHT/736.0), 40*(WIDTH/414.0), 40*(HEIGHT/736.0))];
    [ViewTool setLableFont14:weekmovebutt.titleLabel];
    [weekmovebutt setBackgroundImage:[UIImage imageNamed:_endbuttImageName] forState:UIControlStateNormal];
    
    weekmovebutt.tag = 4;
    
    [weekmovebutt addTarget:self action:@selector(weekclick:) forControlEvents:UIControlEventTouchUpInside];
    
    weekStartimage = [[UIImageView alloc] initWithFrame:CGRectMake(weekstartView.center.x, weekmovebutt.y, 0, 40*(HEIGHT/736.0))];
    weekStartimage.image = [UIImage imageNamed:_ConnectImageName];
    
    
    [weekScroll addSubview:weekStartimage];
    
    [self setTitData:nil withnum:a];
    
    [weekScroll addSubview:weekstartView];
    [weekScroll addSubview:weekendView];
    
    //    weekMoveimage = [[UIImageView alloc] initWithFrame:CGRectMake(weekstartView.center.x, weekmovebutt.y, 0, 40*(HEIGHT/736.0))];
    //    weekMoveimage.image = [UIImage imageNamed:_ConnectImageName];
    //
    //    weekMoveimage.alpha = 0.8;
    //
    //    [weekScroll addSubview:weekMoveimage];
    
    //    int todayDay = (int)[DateTools getDateInfobydate:[NSDate date]].day;
    
    [weekstartbutt setTitle:@"今" forState:UIControlStateNormal];
    [weekmovebutt setTitle:@"今" forState:UIControlStateNormal];
    [weekstartView addSubview:weekstartbutt];
    [weekendView addSubview:weekmovebutt];
    
    weekpanGestureRecognizer1 = [[UIPanGestureRecognizer alloc] initWithTarget:self
                                                                        action:@selector(weekhandlePanGestures1:)];
    
    weekpanGestureRecognizer1.delegate = self;
    weekpanGestureRecognizer1.minimumNumberOfTouches = 1;
    weekpanGestureRecognizer1.maximumNumberOfTouches = 1;
    
    weekpanGestureRecognizer2 = [[UIPanGestureRecognizer alloc] initWithTarget:self
                                                                        action:@selector(weekhandlePanGestures2:)];
    weekpanGestureRecognizer2.delegate = self;
    weekpanGestureRecognizer2.minimumNumberOfTouches = 1;
    weekpanGestureRecognizer2.maximumNumberOfTouches = 1;
    
    [weekstartView addGestureRecognizer:weekpanGestureRecognizer1];
    [weekendView addGestureRecognizer:weekpanGestureRecognizer2];
    
}

- (void)weekhandlePanGestures1:(UIPanGestureRecognizer*)paramSender{
//    int today = (int)[[DateTools getDateInfobydate:[NSDate date]] day];
    
    if (paramSender.state != UIGestureRecognizerStateEnded && paramSender.state != UIGestureRecognizerStateFailed){
        //通过使用 locationInView 这个方法,来获取到手势的坐标
        CGPoint location = [paramSender locationInView:paramSender.view.superview];
        if (monthOne == 7) {
            monthOne = 0;
        }
        int x = ceilf((float)(location.x/VIEW_WIDTH));
        int num = (int)[DateTools getNumberOfDaysInMonthbydate:[NSDate date]];
        
        //改变拖动的按钮坐标
         if (x > monthOne && x < monthOne + num + 1) {
        weekstartView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*(x-1), VIEW_HEIGHT/2.0);
        weekstartView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
        
        [weekstartbutt setTitle:[NSString stringWithFormat:@"%d",x-monthOne] forState:UIControlStateNormal];
        
            if (x-monthOne == todayNumber) {
                [weekstartbutt setTitle:@"今" forState:UIControlStateNormal];
            }
        
        //通过比较两个view的位置 来改变连接图片
        [self weekchanggeconnectImage];
        }
    }
    if (paramSender.state == UIGestureRecognizerStateEnded)
    {
        [self weekDoublebuttclick:startbutt Double:movebutt];
    }
}

- (void)weekhandlePanGestures2:(UIPanGestureRecognizer*)paramSender{
//    int today = (int)[[DateTools getDateInfobydate:[NSDate date]] day];
    if (paramSender.state != UIGestureRecognizerStateEnded && paramSender.state != UIGestureRecognizerStateFailed){
        //通过使用 locationInView 这个方法,来获取到手势的坐标
        CGPoint location = [paramSender locationInView:paramSender.view.superview];
        if (monthOne == 7) {
            monthOne = 0;
        }
        int x = ceilf((float)(location.x/VIEW_WIDTH));
        int num = (int)[DateTools getNumberOfDaysInMonthbydate:[NSDate date]];
        
        //改变拖动的按钮坐标
        if (x > monthOne && x < monthOne + num + 1) {
            weekendView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*(x-1), VIEW_HEIGHT/2.0);
            weekendView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
            
            [weekmovebutt setTitle:[NSString stringWithFormat:@"%d",x-monthOne] forState:UIControlStateNormal];
                if (x-monthOne == todayNumber) {
                    [weekmovebutt setTitle:@"今" forState:UIControlStateNormal];
                    
                }
            NSLog(@"897----------------------  %d    ",x);
            if (x == 14) {

                [UIView animateWithDuration:1 animations:^{
                    weekScroll.contentOffset = CGPointMake(LEFT_WIDTH+VIEW_WIDTH*7*(point.y+1), 0);
                    
                }];

            }
//                else if (x > 7) {
//                NSLog(@"786----------------------  %d  %d  ",(int)weekendView.x,(int)weekScroll.contentOffset.x);
//                [UIView animateWithDuration:1 animations:^{
//                    weekScroll.contentOffset = CGPointMake(LEFT_WIDTH+VIEW_WIDTH*7*point.y, 0);
//                    
//                }];
//            }
            
            


            [self weekchanggeconnectImage];

        }
    }
    if (paramSender.state == UIGestureRecognizerStateEnded)
    {
        [self weekDoublebuttclick:startbutt Double:movebutt];
    }
}

- (void)weekchanggeconnectImage
{
    //判断两个按钮 左右 位置是否有偏移
    int bnt = weekendView.center.x - weekstartView.center.x;
    //根据两个按钮左右位置的差值来改变connect图片的大小和方向 并改变底部label的标题
    if (bnt > 0) {
        weekStartimage.frame = CGRectMake(weekstartView.center.x, weekstartbutt.y, weekendView.center.x - weekstartView.center.x, 40*(HEIGHT/736.0));
        weekstartLab.text = _startBottomLabText;
        weekendLab.text = _endBottomLabText;
    }
    
    else if (bnt < 0){
        weekStartimage.frame = CGRectMake(weekstartView.center.x, weekstartbutt.y, weekendView.center.x - weekstartView.center.x, 40*(HEIGHT/736.0));
        weekstartLab.text = _endBottomLabText;
        weekendLab.text = _startBottomLabText;
        
    }
    else {
        weekStartimage.frame = CGRectMake(weekstartView.center.x, weekstartbutt.y, 0, 40*(HEIGHT/736.0));
        weekstartLab.text = @"";
        weekendLab.text = @"";
    }
    [weekScroll bringSubviewToFront:weekstartView];
    [weekScroll bringSubviewToFront:weekendView];
    
}

- (void)weekclick:(UIButton *)butt
{
    isButtClick = YES;
    int sx = weekstartView.frame.origin.x/VIEW_WIDTH;
    int ex = weekendView.frame.origin.x/VIEW_WIDTH;
        if (monthOne == 7) {
            monthOne = 0;
        }
    NSString *SingleSelected = [NSString string];
    SingleSelected = [NSString stringWithFormat:@"%d",ex+1-monthOne];
    NSLog(@"******************&&&&&&&    %@",SingleSelected);
    
    //第一个按钮
    if (butt.tag == 3) {
        
        weekstartView.frame = CGRectMake(VIEW_WIDTH*(sx), 0, VIEW_WIDTH, VIEW_HEIGHT);
        weekendView.frame = CGRectMake(VIEW_WIDTH*(sx), 0, VIEW_WIDTH, VIEW_HEIGHT);
    }
    //第二个按钮
    if (butt.tag == 4){
        
        weekstartView.frame = CGRectMake(VIEW_WIDTH*(ex), 0, VIEW_WIDTH, VIEW_HEIGHT);
        weekendView.frame = CGRectMake(VIEW_WIDTH*(ex), 0, VIEW_WIDTH, VIEW_HEIGHT);
    }
    
    weekStartimage.frame = CGRectMake(weekstartView.center.x, 10, 0, 40*(HEIGHT/736.0));
    //    Moveimage.frame = CGRectMake(startView.center.x, 5, 0, 50);
    weekstartLab.text = @"";
    weekendLab.text = @"";
    
        [weekstartbutt setTitle:SingleSelected forState:UIControlStateNormal];
        [weekmovebutt setTitle:SingleSelected forState:UIControlStateNormal];
    
    //    NSString *datestr1 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    
    NSDateComponents *comps = [DateTools getDateInfobydate:CeshiDate];
    NSString *str1= [NSString stringWithFormat:@"%d",(int)comps.year];
    NSString *str2= [NSString stringWithFormat:@"%d",(int)comps.month];
    NSString *str3= [NSString stringWithFormat:@"%d",(int)comps.day];
    if ([SingleSelected isEqualToString:str3]) {
            [weekstartbutt setTitle:@"今" forState:UIControlStateNormal];
       
            [weekmovebutt setTitle:@"今" forState:UIControlStateNormal];
    }
    
    if ([str2 intValue]<10) {
        str2 = [NSString stringWithFormat:@"0%@",str2];
    }
    if ([SingleSelected intValue]<10) {
        SingleSelected = [NSString stringWithFormat:@"0%@",SingleSelected];
    }
    
    if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(currentSelectedDateYear:Month:Day:
                                                                                      )]){
        [self.HEClanderDelegate currentSelectedDateYear:str1 Month:str2 Day:SingleSelected];
    }
    isButtClick = NO;
}

- (void)weekDoublebuttclick:(UIButton *)firButt Double:(UIButton *)secButt
{
    isButtClick = YES;
    int sx = weekstartView.frame.origin.x/VIEW_WIDTH;
    int ex = weekendView.frame.origin.x/VIEW_WIDTH;
    
    NSString *SingleSelected = [NSString string];
    NSString *DoubleSelected = [NSString string];
    
    if (monthOne == 7) {
        monthOne = 0;
    }
    
    SingleSelected = [NSString stringWithFormat:@"%d",sx+1-monthOne];
    
    DoubleSelected = [NSString stringWithFormat:@"%d",ex+1-monthOne];
    
    //    NSString *datestr1 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    //
    //    NSString *datestr2 = [self pingjieDate:[DoubleSelected intValue] date:CeshiDate];
    //
    //    if (sx > ex) {
    //        datestr2 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    //
    //        datestr1 = [self pingjieDate:[DoubleSelected intValue] date:CeshiDate];
    //    }else if (sx < ex){
    //        datestr1 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    //
    //        datestr2 = [self pingjieDate:[DoubleSelected intValue] date:CeshiDate];
    //    }
    //    else if (sx == ex){
    //
    //        datestr1 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    //
    //        datestr2 = [self pingjieDate:[DoubleSelected intValue] date:CeshiDate];
    //
    //    }
    
    
    NSDateComponents *comps = [DateTools getDateInfobydate:CeshiDate];
    NSString *str1= [NSString stringWithFormat:@"%d",(int)comps.year];
    NSString *str2= [NSString stringWithFormat:@"%d",(int)comps.month];
    
    
    if ([str2 intValue]<10) {
        str2 = [NSString stringWithFormat:@"0%@",str2];
    }
    if ([SingleSelected intValue]<10) {
        SingleSelected = [NSString stringWithFormat:@"0%@",SingleSelected];
    }
    if ([DoubleSelected intValue]<10) {
        DoubleSelected = [NSString stringWithFormat:@"0%@",DoubleSelected];
    }
    
    if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(currentSelectedDate: DoubleSelected:Year:Month:
                                                                                      )]){
        [self.HEClanderDelegate currentSelectedDate:SingleSelected DoubleSelected:DoubleSelected Year:str1 Month:str2];
    }
    isButtClick = NO;
}

//计算星期日历的数据
- (void)setTitData:(NSMutableArray *)array withnum:(int)num
{
    int any = (int)[DateTools getDateInfobydate:[NSDate date]].day;
    for (int i = 0; i < num ; i ++) {
        
        if (i < num) {
            TableViewCellButton *butt = [[TableViewCellButton alloc] initWithFrame:CGRectMake(VIEW_WIDTH*i+10*(WIDTH/414.0), 15*(HEIGHT/736.0), 40*(WIDTH/414.0), 40*(HEIGHT/736.0))];
            [butt setTitle:[dateArr objectAtIndex:i] forState:UIControlStateNormal];
            butt.tag = [[dateArr objectAtIndex:i] integerValue];
            butt.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
            [ViewTool setLableFont14:butt.titleLabel];
            if ([butt.titleLabel.text isEqualToString:@"今"]) {
                //            NSLog(@"0000------------------------  %d  " , [str intValue]);
                [butt setBackgroundImage:[UIImage imageNamed:@"HY_date_bg_today"] forState:UIControlStateNormal];
                butt.tag = any;
            }
            [butt addTarget:self action:@selector(weekButtonClick:) forControlEvents:UIControlEventTouchUpInside];
            [weekScroll addSubview:butt];
            [WeekButtArr addObject:butt];
        }
    }
}

- (void)weekButtonClick:(UIButton *)butt
{
    isButtClick = YES;
    NSString *datestr = [self pingjieDate:(int)butt.tag date:[NSDate date]];
    
    NSDate *date = [DateTools strToDate:datestr];
    int any = (int)[DateTools getDateInfobydate:date].day;
//    int today = (int)[DateTools getDateInfobydate:[NSDate date]].day;
    if (weekmonthOne == 7) {
        weekmonthOne = 0;
    }
    int todayNum = any + weekmonthOne;
    weekstartView.frame = CGRectMake(VIEW_WIDTH*(todayNum-1), 0, VIEW_WIDTH, VIEW_HEIGHT+10);
    weekendView.frame = CGRectMake(VIEW_WIDTH*(todayNum-1), 0, VIEW_WIDTH, VIEW_HEIGHT+10);
    
    weekStartimage.frame = CGRectMake(weekstartView.center.x, 10, 0, 40*(HEIGHT/736.0));
    weekMoveimage.frame = CGRectMake(weekstartView.center.x, 10, 0, 40*(HEIGHT/736.0));
    weekstartLab.text = @"";
    weekendLab.text = @"";
    
    [weekstartbutt setTitle:[NSString stringWithFormat:@"%d",(int)butt.tag] forState:UIControlStateNormal];
    [weekmovebutt setTitle:[NSString stringWithFormat:@"%d",(int)butt.tag] forState:UIControlStateNormal];
    
        if (butt.tag == todayNumber) {
            [weekmovebutt setTitle:@"今" forState:UIControlStateNormal];
            [weekstartbutt setTitle:@"今" forState:UIControlStateNormal];
        }
    
    NSDateComponents *comps = [DateTools getDateInfobydate:CeshiDate];
    NSString *str1= [NSString stringWithFormat:@"%d",(int)comps.year];
    NSString *str2= [NSString stringWithFormat:@"%d",(int)comps.month];
    
    NSString *str3= [NSString stringWithFormat:@"%d",(int)butt.tag];
    
    
    
    if ([str2 intValue]<10) {
        str2 = [NSString stringWithFormat:@"0%@",str2];
    }
    if ([str3 intValue]<10) {
        str3 = [NSString stringWithFormat:@"0%@",str3];
    }
    
    if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(currentSelectedDateYear:Month:Day:
                                                                                      )]){
        [self.HEClanderDelegate currentSelectedDateYear:str1 Month:str2 Day:str3];
    }
    isButtClick = NO;
}

- (void)move:(int)direction
{
    isMove = YES;
    
    view1 = [[UIView alloc] initWithFrame:CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, WIDTH-LEFT_WIDTH, VIEW_HEIGHT*tableHeightNum+15)];
    view1.backgroundColor = NavBackColor;
    [self addSubview:view1];
    
    table1 = [[UITableView alloc] initWithFrame:MoveView.bounds style:UITableViewStylePlain];
    table1.tag = 1;
    table1.delegate = self;
    table1.dataSource = self;
    table1.separatorStyle = UITableViewCellSeparatorStyleNone;
    table1.backgroundColor = NavBackColor;
    [view1 addSubview:table1];
    
    [self bringSubviewToFront:view1];
    
    [UIView animateWithDuration:0.3 animations:^{
        
        view1.transform = CGAffineTransformMakeTranslation(-direction*WIDTH, 0);
        
    } completion:^(BOOL finished) {
        
        [self getCount];
        self.frame = CGRectMake(0, 0, WIDTH, 75+VIEW_HEIGHT*tableHeightNum +20);
        
        if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(clanderDragUpAndDown
                                                                                          )]){
            [self.HEClanderDelegate clanderDragUpAndDown];
        }
        
        [view1 removeFromSuperview];
        CeshiDate1 = CeshiDate;
        dateArr1 = [DateTools getDatesourcebyDate:CeshiDate1];
    }];
    isMove = NO;
}

- (void)swipe:(UISwipeGestureRecognizer *)swipe
{
    
    if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
        NSLog(@"右");
        
        [self ChangeMonth:leftButt];
        [self move:-1];
    }
    else if (swipe.direction == UISwipeGestureRecognizerDirectionLeft)
    {
        NSLog(@"左");
        
        [self ChangeMonth:rightButt];
        [self move:1];
        
    }
    [UIView animateWithDuration:0.2 animations:^{
        if (swipe.direction == UISwipeGestureRecognizerDirectionUp)
        {
            self.frame = CGRectMake(0, 0, WIDTH, 85+VIEW_HEIGHT);
            MoveView.frame = CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, WIDTH, 0);
            remanidView.frame = CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, WIDTH, 0);
            remanidView.hidden = YES;
            weekScroll.frame = CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, VIEW_WIDTH*7, VIEW_HEIGHT+15);
            corview.frame = CGRectMake(VIEW_WIDTH*7, RILIVIEW_WIDTH, WIDTH - VIEW_WIDTH*7, VIEW_HEIGHT+15);
            [weekScroll addGestureRecognizer:downSwipe];
            int any = (int)[DateTools getDateInfobydate:[NSDate date]].day;
            CGPoint point = [self getXYbyDay:any];
            int y = point.y;
            weekScroll.contentOffset = CGPointMake(VIEW_WIDTH*7*y, 0);
            endDate = CeshiDate;
            CeshiDate = [NSDate date];
            
            NSString *title = [[DateTools getYearAndMonth:[NSDate date]] objectAtIndex:0];
            TitleLabel.text = title;
            
            if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(clanderDragUpAndDown
                                                                                              )]){
                [self.HEClanderDelegate clanderDragUpAndDown];
            }
            
            isExpand = NO;
            MoveView.hidden = YES;
            table.hidden = YES;
            weekScroll.hidden = NO;
            
        }
        else if (swipe.direction == UISwipeGestureRecognizerDirectionDown)
        {
            self.frame = CGRectMake(0, 0, WIDTH, 75+VIEW_HEIGHT*tableHeightNum +20);
            MoveView.frame = CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, WIDTH, VIEW_HEIGHT*6+15 +20);
            remanidView.frame = CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, WIDTH-LEFT_WIDTH, VIEW_HEIGHT*tableHeightNum);
            remanidView.hidden = NO;
            weekScroll.frame = CGRectMake(LEFT_WIDTH, RILIVIEW_WIDTH, VIEW_WIDTH*7, 0);
            corview.frame = CGRectMake(VIEW_WIDTH*7, RILIVIEW_WIDTH, WIDTH - VIEW_WIDTH*7, 0);
            [weekScroll removeGestureRecognizer:downSwipe];
            
            if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(clanderDragUpAndDown
                                                                                              )]){
                [self.HEClanderDelegate clanderDragUpAndDown];
            }
            if (isExpand == NO) {
                CeshiDate = endDate;
                NSString *title = [[DateTools getYearAndMonth:endDate] objectAtIndex:0];
                TitleLabel.text = title;
                
            }
            isExpand = YES;
            MoveView.hidden = NO;
            table.hidden = NO;
            weekScroll.hidden = YES;

            //            NSLog(@"下下下下");
        }
    }];
}

- (void)handlePanGestures1:(UIPanGestureRecognizer*)paramSender{
    int Y = [self getDayCountOfMonth:CeshiDate];
    if (monthOne == 7) {
        monthOne = 0;
    }
    int num = ceilf((float)(Y + monthOne)/7);
    int rem = (Y + monthOne)%7;
//    int today = (int)[[DateTools getDateInfobydate:[NSDate date]] day];
    if (paramSender.state != UIGestureRecognizerStateEnded && paramSender.state != UIGestureRecognizerStateFailed){
        //通过使用 locationInView 这个方法,来获取到手势的坐标
        CGPoint location = [paramSender locationInView:paramSender.view.superview];
        int x = location.x/VIEW_WIDTH;
        int y = location.y/VIEW_HEIGHT;
        
        //限制按钮的 拖拽区域
        if (location.y > 0 && location.y < VIEW_HEIGHT && location.x > monthOne*VIEW_WIDTH && location.x < 7*VIEW_WIDTH) {
            //改变拖动的按钮坐标
            startView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*x, VIEW_HEIGHT/2.0+VIEW_HEIGHT*y);
            startView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
            [startbutt setTitle:[NSString stringWithFormat:@"%d",x+1+7*y- monthOne] forState:UIControlStateNormal];
            [self changgeconnectImage];
        }if (rem != 0 && location.x < 7*VIEW_WIDTH) {
            if (location.y > VIEW_HEIGHT && location.y < (num-1)*VIEW_HEIGHT){
                startView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*x, VIEW_HEIGHT/2.0+VIEW_HEIGHT*y);
                startView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
                [self changgeconnectImage];
                [startbutt setTitle:[NSString stringWithFormat:@"%d",x+1+7*y- monthOne] forState:UIControlStateNormal];
            }
            else if (location.y > (num-1)*VIEW_HEIGHT && location.y < num*VIEW_HEIGHT&& location.x < rem*VIEW_WIDTH) {
                startView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*x, VIEW_HEIGHT/2.0+VIEW_HEIGHT*y);
                startView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
                [self changgeconnectImage];
                [startbutt setTitle:[NSString stringWithFormat:@"%d",x+1+7*y- monthOne] forState:UIControlStateNormal];
            }
        }else if (rem == 0 && location.x < 7*VIEW_WIDTH){
            if (location.y > VIEW_HEIGHT && location.y < (num)*VIEW_HEIGHT){
                startView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*x, VIEW_HEIGHT/2.0+VIEW_HEIGHT*y);
                startView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
                [self changgeconnectImage];
                [startbutt setTitle:[NSString stringWithFormat:@"%d",x+1+7*y- monthOne] forState:UIControlStateNormal];
            }
        }
        if (CeshiDate == [NSDate date]) {
            if (x+1+7*y- monthOne == todayNumber) {
                [startbutt setTitle:@"今" forState:UIControlStateNormal];
            }
        }
//        NSLog(@"000000      111111    %d   %d",x,y);
    }
    if (paramSender.state == UIGestureRecognizerStateEnded)
    {
        [self Doublebuttclick:startbutt Double:movebutt];
    }
}

- (void)handlePanGestures2:(UIPanGestureRecognizer*)paramSender{
    int Y = [self getDayCountOfMonth:CeshiDate];
    if (monthOne == 7) {
        monthOne = 0;
    }
    int num = ceilf((float)(Y + monthOne)/7);
    int rem = (Y + monthOne)%7;
    movebutt.roundView.hidden = YES;

//    int today = (int)[[DateTools getDateInfobydate:[NSDate date]] day];
    if (paramSender.state != UIGestureRecognizerStateEnded && paramSender.state != UIGestureRecognizerStateFailed){
        //通过使用 locationInView 这个方法,来获取到手势的坐标
        CGPoint location = [paramSender locationInView:paramSender.view.superview];
        int x = location.x/VIEW_WIDTH;
        int y = location.y/VIEW_HEIGHT;
        //        NSLog(@"000000      222222    %d ",num);
        //限制按钮的 拖拽区域
        if (location.y > 0 && location.y < VIEW_HEIGHT && location.x > monthOne*VIEW_WIDTH && location.x < 7*VIEW_WIDTH) {
            //改变拖动的按钮坐标
            endView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*x, VIEW_HEIGHT/2.0+VIEW_HEIGHT*y);
            endView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
            [movebutt setTitle:[NSString stringWithFormat:@"%d",x+1+7*y- monthOne] forState:UIControlStateNormal];
            [self changgeconnectImage];
        }if (rem != 0 && location.x < 7*VIEW_WIDTH) {
            if (location.y > VIEW_HEIGHT && location.y < (num-1)*VIEW_HEIGHT){
                endView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*x, VIEW_HEIGHT/2.0+VIEW_HEIGHT*y);
                endView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
                [self changgeconnectImage];
                [movebutt setTitle:[NSString stringWithFormat:@"%d",x+1+7*y- monthOne] forState:UIControlStateNormal];
            }
            else if (location.y > (num-1)*VIEW_HEIGHT && location.y < num*VIEW_HEIGHT&& location.x < rem*VIEW_WIDTH) {
                endView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*x, VIEW_HEIGHT/2.0+VIEW_HEIGHT*y);
                endView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
                [self changgeconnectImage];
                [movebutt setTitle:[NSString stringWithFormat:@"%d",x+1+7*y- monthOne] forState:UIControlStateNormal];
            }
        }else if (rem == 0 && location.x < 7*VIEW_WIDTH){
            if (location.y > VIEW_HEIGHT && location.y < (num)*VIEW_HEIGHT){
                endView.center = CGPointMake(VIEW_WIDTH/2.0 + VIEW_WIDTH*x, VIEW_HEIGHT/2.0+VIEW_HEIGHT*y);
                endView.bounds = CGRectMake(0, 0, VIEW_WIDTH, VIEW_HEIGHT);
                [self changgeconnectImage];
                [movebutt setTitle:[NSString stringWithFormat:@"%d",x+1+7*y- monthOne] forState:UIControlStateNormal];
            }
        }
        if (CeshiDate == [NSDate date]) {
            if (x+1+7*y- monthOne == todayNumber) {
                [movebutt setTitle:@"今" forState:UIControlStateNormal];
            }
        }
        
    }
    if (paramSender.state == UIGestureRecognizerStateEnded)
    {
        [self Doublebuttclick:startbutt Double:movebutt];
    }
}

- (void)changgeconnectImage
{
    //判断两个按钮上下 左右 位置是否有偏移
    ant = endView.center.y - startView.center.y;
    int bnt = endView.center.x - startView.center.x;
    int a = startView.frame.origin.y/VIEW_HEIGHT;
    int b = endView.frame.origin.y/VIEW_HEIGHT;
    //根据两个按钮上下位置的差值来改变两个按钮所在cell的connect图片的大小和反向 并改变底部label的标题
    //第二个按钮在下方
    if (ant > 0) {
        Startimage.frame = CGRectMake(startView.center.x, startView.frame.origin.y+10, WIDTH - startView.center.x, 40*(HEIGHT/736.0));
        Moveimage.frame = CGRectMake(0, endView.frame.origin.y+10, endView.center.x, 40*(HEIGHT/736.0));
        //_ConnectImageName = @"1_Bg";
        startLab.text = _startBottomLabText;
        endLab.text = _endBottomLabText;
        //让两个按钮之间的cell的connect图片显示
        for (UIImageView *img in ConnectImageArr) {
            if (img.tag > a && img.tag < b ) {
//                NSLog(@"??????????????????????????????");
                img.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:_ConnectImageName]];
            }else{
                img.backgroundColor = [UIColor clearColor];
            }
        }
    }
    //第一个按钮在下方
    else if (ant < 0){
        Startimage.frame = CGRectMake(0, startView.frame.origin.y+10, startView.center.x, 40*(HEIGHT/736.0));
        Moveimage.frame = CGRectMake(endView.center.x, endView.frame.origin.y+10, WIDTH- endView.center.x, 40*(HEIGHT/736.0));
        //_ConnectImageName = @"1_Bg";
        startLab.text = _endBottomLabText;
        endLab.text = _startBottomLabText;
        
        for (UIImageView *img in ConnectImageArr) {
            if (img.tag < a && img.tag > b ) {
                img.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:_ConnectImageName]];
            }else{
                img.backgroundColor = [UIColor clearColor];
            }
        }
    }
    else {
        Startimage.frame = CGRectMake(startView.center.x, startView.frame.origin.y+10, 0, 40*(HEIGHT/736.0));
        Moveimage.frame = CGRectMake(startView.center.x, endView.frame.origin.y+10, endView.center.x - startView.center.x, 40*(HEIGHT/736.0));
        //        _ConnectImageName = @"";
        if (bnt > 0) {
            startLab.text = _startBottomLabText;
            endLab.text = _endBottomLabText;
        }else if (bnt < 0){
            startLab.text = _endBottomLabText;
            endLab.text = _startBottomLabText;
        }else{
            startLab.text = @"";
            endLab.text = @"";
        }
    }
    [table bringSubviewToFront:startView];
    [table bringSubviewToFront:endView];
    
    //    NSDateComponents *comps = [DateTools getDateInfobydate:CeshiDate];
    //    NSString *str1= [NSString stringWithFormat:@"%d",(int)comps.year];
    //    NSString *str2= [NSString stringWithFormat:@"%d",(int)comps.month];
    //    NSString *str3= [NSString stringWithFormat:@"%d",(int)comps.day];
    //    if ([str2 intValue]<10) {
    //        str2 = [NSString stringWithFormat:@"0%@",str2];
    //    }
    //    if ([str3 intValue]<10) {
    //        str3 = [NSString stringWithFormat:@"0%@",str3];
    //    }
    //
    //    if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(currentSelectedDateYear:Month:Day:
    //                                                                                      )]){
    //        [self.HEClanderDelegate currentSelectedDateYear:str1 Month:str2 Day:str3];
    //    }
    
}

//-(BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch {
//    if([touch.view isKindOfClass:[UISlider class]])
//        return NO;//不会执行UIGestureRecognizer注册的事件
//    else
//        return YES;//会执行UIGestureRecognizer注册的事件
//}
//
//- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
////    return YES;//UIScrollView 和 子View上的UIPanGestureRecognizer都会响应
//    return NO;//只响应子View上的UIPanGestureRecognizer
//}

- (void)isHaveRemaind:(NSString *)Remaind
{
    
    BOOL istoday = NO;
    for (NSString *str in _remaindArr) {
        if ([Remaind intValue] == [str intValue]) {
            istoday = NO;
            movebutt.roundView.hidden = NO;
            return;
        }else{
             movebutt.roundView.hidden = YES;
        }
    }
}

- (void)buttclick:(UIButton *)butt
{
    isButtClick = YES;
    
    int sy = startView.frame.origin.y/VIEW_HEIGHT;
    int ey = endView.frame.origin.y/VIEW_HEIGHT;
    
    int sx = ceilf((float)(startView.frame.origin.x/VIEW_WIDTH));
    int ex = ceilf((float)(endView.frame.origin.x/VIEW_WIDTH));
    if (monthOne == 7) {
        monthOne = 0;
    }
    int sday,eday;
    NSString *SingleSelected = [NSString string];
    
    //第一个按钮
    if (butt.tag == 0) {
        sday = 7*sy + 1 + sx - monthOne;
        
        //                NSLog(@"000000000     %d ",sx);
        SingleSelected = [NSString stringWithFormat:@"%d",sday];
        startView.frame = CGRectMake(VIEW_WIDTH*(sx), VIEW_HEIGHT*sy, VIEW_WIDTH, VIEW_HEIGHT);
        endView.frame = CGRectMake(VIEW_WIDTH*(sx), VIEW_HEIGHT*sy, VIEW_WIDTH, VIEW_HEIGHT);
    }
    //第二个按钮
    if (butt.tag == 1){
        eday = 7*ey + 1 + ex - monthOne;
        
        //                NSLog(@"1111111111    %d ",ex);
        SingleSelected = [NSString stringWithFormat:@"%d",eday];
        startView.frame = CGRectMake(VIEW_WIDTH*(ex), VIEW_HEIGHT*ey, VIEW_WIDTH, VIEW_HEIGHT);
        endView.frame = CGRectMake(VIEW_WIDTH*(ex), VIEW_HEIGHT*ey, VIEW_WIDTH, VIEW_HEIGHT);
    }
    
    Startimage.frame = CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0));
    Moveimage.frame = CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0));
    startLab.text = @"";
    endLab.text = @"";
    
    for (UIImageView *img in ConnectImageArr) {
        img.backgroundColor = [UIColor clearColor];
    }
    
    NSDateComponents *comps = [DateTools getDateInfobydate:CeshiDate];
    NSString *str1= [NSString stringWithFormat:@"%d",(int)comps.year];
    NSString *str2= [NSString stringWithFormat:@"%d",(int)comps.month];
    NSString *str3= [NSString stringWithFormat:@"%d",(int)comps.day];
    
    NSDateComponents *comps1 = [DateTools getDateInfobydate:[NSDate date]];
    NSString *str4= [NSString stringWithFormat:@"%d",(int)comps1.year];
    NSString *str5= [NSString stringWithFormat:@"%d",(int)comps1.month];
    
    [startbutt setTitle:SingleSelected forState:UIControlStateNormal];
    [movebutt setTitle:SingleSelected forState:UIControlStateNormal];
    [self isHaveRemaind:SingleSelected];

    if ([str1 intValue] == [str4 intValue] && [str2 intValue] == [str5 intValue]) {
        if ([SingleSelected isEqualToString:str3]) {
            [startbutt setTitle:@"今" forState:UIControlStateNormal];
            [movebutt setTitle:@"今" forState:UIControlStateNormal];
        }
    }
    
    if ([str2 intValue]<10) {
        str2 = [NSString stringWithFormat:@"0%@",str2];
    }
    if ([SingleSelected intValue]<10) {
        SingleSelected = [NSString stringWithFormat:@"0%@",SingleSelected];
    }
    
    lastClick = [SingleSelected intValue];
    if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(currentSelectedDateYear:Month:Day:
                                                                                      )]){
        [self.HEClanderDelegate currentSelectedDateYear:str1 Month:str2 Day:SingleSelected];
    }
    isButtClick = NO;
    }

- (void)Doublebuttclick:(UIButton *)firButt Double:(UIButton *)secButt
{
    isButtClick = YES;
    int sy = startView.frame.origin.y/VIEW_HEIGHT;
    int ey = endView.frame.origin.y/VIEW_HEIGHT;
    
    int sx = startView.frame.origin.x/VIEW_WIDTH;
    int ex = endView.frame.origin.x/VIEW_WIDTH;
    if (monthOne == 7) {
        monthOne = 0;
    }
    int sday,eday;
    NSString *SingleSelected = [NSString string];
    NSString *DoubleSelected = [NSString string];
    
    sday = 7*sy + 1 + sx - monthOne;
    
    eday = 7*ey + 1 + ex - monthOne;
    
    if (sday < eday||sday == eday) {
        SingleSelected = [NSString stringWithFormat:@"%d",sday];
        DoubleSelected = [NSString stringWithFormat:@"%d",eday];
    }
    
    if (sday > eday) {
        SingleSelected = [NSString stringWithFormat:@"%d",eday];
        DoubleSelected = [NSString stringWithFormat:@"%d",sday];
    }
    
    //    NSString *datestr1 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    //
    //    NSString *datestr2 = [self pingjieDate:[DoubleSelected intValue] date:CeshiDate];
    //
    //    if (sy > ey) {
    //        datestr2 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    //
    //        datestr1 = [self pingjieDate:[DoubleSelected intValue] date:CeshiDate];
    //    }else if (sy < ey){
    //        datestr1 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    //
    //        datestr2 = [self pingjieDate:[DoubleSelected intValue] date:CeshiDate];
    //    }
    //    else if (sy == ey){
    //        if (sx > ex) {
    //            datestr2 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    //
    //            datestr1 = [self pingjieDate:[DoubleSelected intValue] date:CeshiDate];
    //        }else{
    //            datestr1 = [self pingjieDate:[SingleSelected intValue] date:CeshiDate];
    //
    //            datestr2 = [self pingjieDate:[DoubleSelected intValue] date:CeshiDate];
    //        }
    //    }
    
    ;
    NSDateComponents *comps = [DateTools getDateInfobydate:CeshiDate];
    NSString *str1= [NSString stringWithFormat:@"%d",(int)comps.year];
    NSString *str2= [NSString stringWithFormat:@"%d",(int)comps.month];
    
    if ([str2 intValue]<10) {
        str2 = [NSString stringWithFormat:@"0%@",str2];
    }
    if ([SingleSelected intValue]<10) {
        SingleSelected = [NSString stringWithFormat:@"0%@",SingleSelected];
    }
    if ([DoubleSelected intValue]<10) {
        DoubleSelected = [NSString stringWithFormat:@"0%@",DoubleSelected];
    }
    
    if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(currentSelectedDate: DoubleSelected:Year:Month:
                                                                                      )]){
        [self.HEClanderDelegate currentSelectedDate:SingleSelected DoubleSelected:DoubleSelected Year:str1 Month:str2];
    }
    isButtClick = NO;
}

- (void)setremaindArr:(NSMutableArray *)arr
{
            [self.remaindArr removeAllObjects];
        for (int i = 0; i < arr.count ; i ++) {
            NSString *datestring = [arr objectAtIndex:i];
            NSString *str = [datestring substringToIndex:10];

            NSString *str1 = [str substringFromIndex:8];

            [_remaindArr addObject:str1];
        }
        
            if ( isButtClick == NO) {
                if (monthOne == 7) {
                    monthOne = 0;
                }
                [remanidView setArr:_remaindArr oneMonth:monthOne];
                [self isHaveRemaind:[NSString stringWithFormat:@"%d",lastClick]];
            }
    weekRemaind++;
    if (weekRemaind == 1) {
        WeekRemaindArr = _remaindArr;
    }
    
}

#pragma mark ---------------- UITableview Delegate -------------------
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 5) {
        return VIEW_HEIGHT+5;
    }
    return VIEW_HEIGHT;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return tableCount;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TableViewCell *cell = [TableViewCell cellInitWithTableview:tableView];
    
    //************说明:去掉此句 日历数据无效
//    int one = [DateTools setdate:CeshiDate];
//    NSLog(@"0000------------------------    %d",one);
    if (tableView.tag == 1) {
        cell.backgroundColor = NavBackColor;
        [cell setTitData:dateArr1 remaindArr:nil withIndex:(int)indexPath.row];
        return cell;
    }
    [cell setTitData:dateArr remaindArr:nil withIndex:(int)indexPath.row];
    
    [cell.DateButton addTarget:self action:@selector(selectedDate:) forControlEvents:UIControlEventTouchUpInside];
    [cell.DateTwoButton addTarget:self action:@selector(selectedDate:) forControlEvents:UIControlEventTouchUpInside];
    [cell.DateThrButton addTarget:self action:@selector(selectedDate:) forControlEvents:UIControlEventTouchUpInside];
    [cell.DateForButton addTarget:self action:@selector(selectedDate:) forControlEvents:UIControlEventTouchUpInside];
    [cell.DateFifButton addTarget:self action:@selector(selectedDate:) forControlEvents:UIControlEventTouchUpInside];
    [cell.DateSixButton addTarget:self action:@selector(selectedDate:) forControlEvents:UIControlEventTouchUpInside];
    [cell.DateSevButton addTarget:self action:@selector(selectedDate:) forControlEvents:UIControlEventTouchUpInside];
    
    return cell;
}

- (void)selectedDate:(UIButton *)butt
{
    [self isHaveRemaind:[NSString stringWithFormat:@"%d",(int)butt.tag]];
    isButtClick = YES;
    startView.hidden = NO;
    endView.hidden = NO;
    
    CGPoint point = [self getXYbyDay:(int)butt.tag];
    int x = point.x;
    int y = point.y;
    
    startView.frame = CGRectMake(VIEW_WIDTH*(x-1), VIEW_HEIGHT*y, VIEW_WIDTH, VIEW_HEIGHT);
    endView.frame = CGRectMake(VIEW_WIDTH*(x-1), VIEW_HEIGHT*y, VIEW_WIDTH, VIEW_HEIGHT);
    Startimage.frame = CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0));
    Moveimage.frame = CGRectMake(startView.center.x, 10, 0, 40*(HEIGHT/736.0));
    startLab.text = @"";
    endLab.text = @"";
    for (UIImageView *img in ConnectImageArr) {
        img.backgroundColor = [UIColor clearColor];
    }
    [startbutt setTitle:[NSString stringWithFormat:@"%d",(int)butt.tag]forState:UIControlStateNormal];
    [movebutt setTitle:[NSString stringWithFormat:@"%d",(int)butt.tag]forState:UIControlStateNormal];
    
    //    NSString *datestr = [self pingjieDate:(int)butt.tag date:CeshiDate];
    
    NSDateComponents *comps = [DateTools getDateInfobydate:CeshiDate];
    NSString *str1= [NSString stringWithFormat:@"%d",(int)comps.year];
    NSString *str2= [NSString stringWithFormat:@"%d",(int)comps.month];
    NSString *str4= [NSString stringWithFormat:@"%d",(int)comps.day];
    
    NSDateComponents *comps1 = [DateTools getDateInfobydate:[NSDate date]];
    NSString *str5= [NSString stringWithFormat:@"%d",(int)comps1.year];
    NSString *str6= [NSString stringWithFormat:@"%d",(int)comps1.month];
    
    NSString *str3= [NSString stringWithFormat:@"%d",(int)butt.tag];
    if ([str1 intValue] == [str5 intValue] && [str2 intValue] == [str6 intValue]) {
        if ([str4 isEqualToString:str3]) {
            [startbutt setTitle:@"今" forState:UIControlStateNormal];
            [movebutt setTitle:@"今" forState:UIControlStateNormal];
        }
    }
    
    if ([str2 intValue]<10) {
        str2 = [NSString stringWithFormat:@"0%@",str2];
    }
    if ([str3 intValue]<10) {
        str3 = [NSString stringWithFormat:@"0%@",str3];
    }
    lastClick = [str3 intValue];
    
    if(self.HEClanderDelegate && [self.HEClanderDelegate respondsToSelector:@selector(currentSelectedDateYear:Month:Day:
                                                                                      )]){
        [self.HEClanderDelegate currentSelectedDateYear:str1 Month:str2 Day:str3];
    }
    
    isButtClick = NO;
    
}

- (NSString *)pingjieDate:(int)ant date:(NSDate *)date
{
    NSString *yearAndMonth = [[DateTools getYearAndMonth:date] objectAtIndex:1];
    
    NSString *dateStr = [NSString stringWithFormat:@"%@-%d",yearAndMonth,ant];
    
    //按钮点击的 日期。
    NSDate *date1 = [DateTools strToDate:dateStr];
    NSDateComponents *comps = [DateTools getDateInfobydate:date1];
    NSString *month = [NSString stringWithFormat:@"%d",(int)comps.month];
    NSString *day = [NSString stringWithFormat:@"%d",(int)comps.day];
    
    if ([month intValue] < 10) {
        month = [NSString stringWithFormat:@"0%@",month];
        
    }if ([day intValue] < 10) {
        day = [NSString stringWithFormat:@"0%@",day];
    }
    NSString *dateString = [NSString stringWithFormat:@"%ld-%@-%@",comps.year,month,day];
    
    //    NSLog(@"important --------   tag = %d  date = %@",ant ,dateString);
    return dateString;
}

- (CGPoint)getXYbyDay:(int)day
{
    int ant = day;
    int one = [DateTools setdate:CeshiDate];
    if (one == 7) {
        one = 0;
    }
    //计算点击的 按钮的坐标
    int x = (ant+one)%7;
    int y = (ant+one)/7;
    if (x == 0) {
        x = 7;
        y = y - 1;
    }
    //    NSLog(@"important --------  x = %d y = %d tag = %ld",x,y);
    
    row = y;
    CGPoint Point = CGPointMake(x, y);
    
    return Point;
}

- (int)getDayCountOfMonth:(NSDate *)date
{
    int num = (int)[DateTools getNumberOfDaysInMonthbydate:date];
    return num;
}

#pragma mark ------------------- UIScrollview Delegate --------------------
// 完成拖拽
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    newContentOffsetX = scrollView.contentOffset.x;
    int ant = ceilf( (float)((int)newContentOffsetX/(VIEW_WIDTH*7)) ) - ceilf( (float)((int)oldContentOffsetX/(VIEW_WIDTH*7)) );
    weekCount = weekCount + ant;
    
//    NSLog(@"    %d",weekCount);
    addcount = 0;
    oldContentOffsetX = newContentOffsetX;
    
}

@end
